<template>
	<view>
		<!-- 审核整改单 -->
		<u-popup :show="shVisible" @close="close('rectificationForm_examine')" round="10" closeable>
			<view class="popup-box">
				<u-radio-group v-model="shFormInline.radio" placement="row" activeColor="#3B75FF">
					<u-radio :name="1" label="通过" :customStyle="{ marginRight: '40rpx' }"></u-radio>
					<u-radio :name="2" label="拒绝"></u-radio>
				</u-radio-group>
				<view class="textarea-box">
					<u-textarea v-model="shFormInline.desc" placeholder="输入审批意见"></u-textarea>
				</view>
				<u-button type="primary" text="提交" color="#3B75FF" :customStyle="{ marginTop: '30rpx' }" @click="shSubmit"></u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
export default {
	name: 'engineeringRectificationOperate',
	props: {
		value: {
			type: String,
			default: ''
		},
		oper_item: {
			type: Object,
			default: {}
		}
	},
	data() {
		return {
			shVisible: false,
			shFormInline: {
				radio: 1,
				desc: ''
			}
		};
	},
	watch: {
		value(val) {
			let that = this;
			switch (val) {
				// 上传整改内容
				case 'rectificationForm_submit':
					uni.navigateTo({
						url: '/pagesC/engineeringManagement/scRectificationForm/scRectificationForm?id=' + this.oper_item.id
					});
					this.close();
					break;
				// 审核整改单
				case 'rectificationForm_examine':
					this.shVisible = true;
					break;
				default:
			}
		}
	},
	methods: {
		close(type) {
			switch (type) {
				// 审核整改单
				case 'rectificationForm_examine':
					this.shVisible = false;
					break;
				default:
			}
			this.$emit('update:value', '');
		},
		shSubmit() {
			let shFormInline = this.shFormInline;
			switch (shFormInline.radio) {
				case 1:
					this.rectificationPassed({
						rectification_id: this.oper_item.id,
						reason_refusal: shFormInline.desc || ''
					});
					break;
				case 2:
					if (!shFormInline.desc) {
						uni.showToast({
							title: '请输入审批意见',
							icon: 'error'
						});
						return;
					}
					this.rectificationRejected({
						rectification_id: this.oper_item.id,
						reason_refusal: shFormInline.desc
					});
					break;
				default:
			}
		},
		// 通过整改单申请
		rectificationPassed(obj) {
			uni.showLoading({
				mask: true
			});
			this.$Apipc.rectificationPassed(obj).then((res) => {
				console.log(res, '通过整改单申请');
				uni.hideLoading();
				if (res.code == 200) {
					this.$emit('submit', this.value);
					this.close('rectificationForm_examine');
				}
				uni.showToast({
					icon: res.code == 200 ? 'success' : 'error',
					title: res.message
				});
			});
		},
		// 拒绝整改单申请
		rectificationRejected(obj) {
			uni.showLoading({
				mask: true
			});
			this.$Apipc.rectificationRejected(obj).then((res) => {
				console.log(res, '拒绝整改单申请');
				uni.hideLoading();
				if (res.code == 200) {
					this.$emit('submit', this.value);
					this.close('rectificationForm_examine');
				}
				uni.showToast({
					icon: res.code == 200 ? 'success' : 'error',
					title: res.message
				});
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.popup-title {
	height: 46px;
	border-bottom: 2rpx solid #efefef;
	text-align: center;
	line-height: 46px;
	font-size: 30rpx;
}

.popup-box {
	padding: 30rpx 20rpx 20rpx;

	.textarea-box {
		margin-top: 30rpx;
	}
}
</style>
